import { useUserStore } from '@/store';
import { request } from '@/utils/request';
import CRUD from '@/utils/request/CRUD';
import axios from 'axios';
// 用户仓库
const userStore = useUserStore();
// 材料库信息CRUD
export const materialLibraryCRUD = CRUD('/system/budget-material-data');

// 材料库主表CRUD
export const materialLibraryNameCRUD = CRUD('/system/budget-material-name');

// 导入材料
export function importMaterialData(data: Record<string, any>) {
  return axios.post(`${import.meta.env.VITE_API_URL}${import.meta.env.VITE_API_URL_PREFIX}/system/budget-material-data/import?materialId=${data.materialId}`,
    data.formData,{
      headers: {
        'Content-Type': 'multipart/form-data',
        Authorization: `Bearer ${userStore.token}`,
        'tenant-id': userStore.tenantId
      },
    }
   );
}
// 获取下载模板
export function getimportTemplateMaterialData() {
  return request.get({
    url: '/system/budget-material-data/get-import-template',
    responseType: 'blob',
  },{
    isTransformResponse: false,
  });
}